package com.epfresh.supplier.activity;

import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.util.Log;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
import com.epfresh.api.global.BaseActivity;
import com.epfresh.supplier.R;
import com.epfresh.supplier.fragment.AgentMakeFragment;
import com.epfresh.supplier.fragment.AgentMyFragment;

public class MakeAgentActivity extends BaseActivity {

//    public AgentMakeFragment makeAgentFragment = new AgentMakeFragment();
    private AgentMyFragment myAgentFragment = new AgentMyFragment();
    TextView tvMakeAgent,tvMyAgent;
    FragmentTransaction transaction;
    FragmentManager manager = getSupportFragmentManager();
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        transaction = manager.beginTransaction();
        setContentView(R.layout.activity_make_agent);
        initView();
    }

    @Override
    protected void onRestart() {
        myAgentFragment.recordFragment.reqAgentRecord(0);
        if (myAgentFragment != null) {
            myAgentFragment.applyFragment.reqApplyRecord(0);
        }
//        makeAgentFragment.reqSupplyStoreDyn(0);
        super.onRestart();
    }

    @Override
    public void onClick(View view) {
        super.onClick(view);
        switch (view.getId()) {
            case R.id.tv_make_agent:
                tvMyAgent.setTextColor(Color.parseColor("#999999"));
                tvMyAgent.setBackgroundColor(Color.TRANSPARENT);
                tvMakeAgent.setTextColor(Color.WHITE);
                tvMakeAgent.setBackgroundResource(R.drawable.bd_agent_make_title_press);
//                showFragment(makeAgentFragment);
                break;
            case R.id.tv_my_agent:
                tvMyAgent.setTextColor(Color.WHITE);
                tvMyAgent.setBackgroundResource(R.drawable.bd_agent_make_title_press);
                tvMakeAgent.setTextColor(Color.parseColor("#999999"));
                tvMakeAgent.setBackgroundColor(Color.TRANSPARENT);
//                showFragment(myAgentFragment);
                break;
            case R.id.iv_make_agent_back:
                finish();
                break;
        }
    }
    //隐藏所有的fragment
//    private void hideFragment(){
//        if(transaction!=null&&myAgentFragment != null){
//            transaction.hide(myAgentFragment);
//        }
//        if(transaction!=null&&makeAgentFragment != null){
//            ((AgentMakeFragment)makeAgentFragment).commonDismiss();
//            transaction.hide(makeAgentFragment);
//        }
//    }
//
//    private void showFragment(Fragment fragment){
//        transaction = manager.beginTransaction();
//        if(fragment==null) {
//            if (fragment instanceof AgentMakeFragment) {
//                fragment = new AgentMakeFragment();
//                transaction.add(R.id.fragment_make_agent,fragment,"MakeGENT");
//            } else {
//                fragment = new AgentMyFragment();
//                transaction.add(R.id.fragment_make_agent,fragment,"MyAGENT");
//            }
//        }
//        hideFragment();
//        transaction.show(fragment);
//        transaction.commit();
//    }

//    @Override
//    protected View getToolBar() {
//       return null;
//    }

    private void initView() {
        ivBack = (ImageView) findViewById(R.id.iv_make_agent_back);
        tvMakeAgent = (TextView) findViewById(R.id.tv_make_agent);
        tvMyAgent = (TextView) findViewById(R.id.tv_my_agent);
        ivBack.setOnClickListener(this);
        tvMyAgent.setOnClickListener(this);
        tvMakeAgent.setOnClickListener(this);
        transaction.add(R.id.fragment_make_agent,myAgentFragment,"MyAGENT");

//        transaction.add(R.id.fragment_make_agent,makeAgentFragment,"MAKEAGENT");
//        hideFragment();
//        transaction.show(makeAgentFragment).commit();
        transaction.show(myAgentFragment).commit();
        setToolbarTitle("我的代办");
    }

    @Override
    public void onSaveInstanceState(Bundle outState) {
        //记录当前fragment的下标
        /*outState.putInt(Constant.KEY_HOME_STATE_INDEX, currentFragmentIndex);
        outState.putInt("orderType", orderType);*/
        super.onSaveInstanceState(outState);
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);

        if (requestCode == 0x65 && resultCode == RESULT_OK) {
        }
    }
}
